package tr.gov.tubitak.bilgem.esya.certviewer;

import tr.gov.tubitak.bilgem.esya.certviewer.viwerasn.ECertField;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 01.12.2011
 * Time: 13:28
 * To change this template use File | Settings | File Templates.
 */
public class ECertFieldTableModel extends DefaultTableModel {
    List<ECertField> certFieldList;

    public ECertFieldTableModel(List<ECertField> certFieldList) {
        this.certFieldList = certFieldList;
    }

    @Override
    public int getRowCount() {
        if(certFieldList == null)
        {
            return 0;
        }
        else
        {
            return  certFieldList.size();
        }
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    ECertField getRowElement(int row)
    {
        return certFieldList.get(row);
    }

    @Override
    public String getColumnName(int column) {
        switch (column)
        {
            case 0:
                return Bundle.getString("ECertFieldTableModel.Field");
            case 1:
                return  Bundle.getString("ECertFieldTableModel.Value");
            default:
                return Bundle.getString("General.Unknown");
        }
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    @Override
    public Object getValueAt(int row, int column) {
        if(certFieldList == null)
        {
            return "";
        }
        else
        {
            ECertField certField = certFieldList.get(row);
            Object retObj="";
            switch (column)
            {
                case 0:
                  retObj = certField;
                  break;
                case 1:
                    retObj=certField.getShortValue();
                    break;
                default:
                    retObj="";
            }
            return retObj;
        }
    }
}
